﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Scoot.Data.Members
{
    public class MemberRepository : IMemberRepository
    {
        private ScootEntities context;

        public MemberRepository()
        {
            context = new ScootEntities();
        }

        public void Create(Member member)
        {
			member.MemberPK = Guid.NewGuid();

			context.Members.Add(member);
			context.SaveChanges();
        }

        public void Edit(Guid key, Member member)
        {
			var update = context.Members
							.Where(m => m.MemberPK == key)
							.Single();

			update.Name = member.Name;
			update.IsActive = member.IsActive;

			context.SaveChanges();
        }

        public IQueryable<Member> GetQueryable()
        {
            return context.Members;
        }

		public void Retire(Guid key)
		{
			var retire = context.Members
							.Where(m => m.MemberPK == key)
							.Single();

			retire.IsActive = false;

			context.SaveChanges();
		}
	}
}
